﻿Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient

Public Class Form1
    Dim MySQLcnn As New MySqlConnection(My.Settings.MySQLConnectionString)
    Dim MSSQLcnn As New SqlConnection(My.Settings.MSSQLConnectionString)

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Using ds As New DataSet()
            Using myAdapter As New MySqlDataAdapter()
                Using da As New SqlDataAdapter("SELECT * FROM Contactos", MSSQLcnn)
                    da.Fill(ds, "Contactos")
                End Using
                Try

                    For Each contacto As DataRow In ds.Tables("Contactos").Rows
                        Dim insert As String = String.Format("INSERT INTO contactos (IdContacto, Nombre, Apellido) VALUES ({0},'{1}','{2}')", contacto(0), contacto(1), contacto(2))

                        myAdapter.InsertCommand = New MySqlCommand(insert, MySQLcnn)
                        MySQLcnn.Open()
                        myAdapter.InsertCommand.ExecuteNonQuery()
                        MySQLcnn.Close()
                    Next
                    
                    MsgBox("OK")
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
            End Using
        End Using

    End Sub

End Class
